package com.myapp.mobilesafe.view;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.myapp.mobilesafe.activity.R;

/**
 * Created by lijie on 2016/4/26.
 */
public class SettingItemView extends RelativeLayout {
    private final String NAMESPACE = "http://schemas.android.com/apk/res-auto";
    private TextView tvTitle;
    private TextView tvDesc;
    private CheckBox checkBox ;
    private String updateON;
    private String updateOff;
    public SettingItemView(Context context) {
        super(context);
        initView();
    }

    public SettingItemView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView();
        int count = attrs.getAttributeCount();
        for(int i=0;i<count;i++){
            String attributeName = attrs.getAttributeName(i);
            String attributevalue = attrs.getAttributeValue(i);
            Log.i("hahah",attributeName+"##===##"+attributevalue);
        }
        String title = attrs.getAttributeValue(NAMESPACE,"updatetitle");
        updateON = attrs.getAttributeValue(NAMESPACE,"desc_on");
        updateOff = attrs.getAttributeValue(NAMESPACE,"desc_off");
        tvTitle.setText(title);
    }

    public SettingItemView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView();
    }
    private void initView(){
        View view =  View.inflate(getContext(), R.layout.setting_item,null);
         tvTitle = (TextView) view.findViewById(R.id.setting_tv1);
         tvDesc = (TextView) view.findViewById(R.id.setting_tv2);
         checkBox = (CheckBox) view.findViewById(R.id.checkbox);
        this.addView(view);
    }
    public void setTvTitle(String title){
        tvTitle.setText(title);
    }
    public void setTvDesc(String desc){
        tvDesc.setText(desc);
    }
    public Boolean isChecked(){
        return checkBox.isChecked();
    }
    public void setChecked(Boolean checked){
        checkBox.setChecked(checked);
        if(checked){
            tvDesc.setText(updateON);
        }else {
            tvDesc.setText(updateOff);
        }
    }
}
